package com.example.propertyeditor;

import java.beans.PropertyEditorSupport;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @Date 2022/1/20
 * @Created by Jonathan
 */
public class DatePropertyEditor extends PropertyEditorSupport {

	/**
	 * 配置文件里面的日期字符串转换给为日期
	 * @param text 日期字符串
	 */

	@Override
	public void setAsText(String text) throws IllegalArgumentException {
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");

		try {
			Date parse = format.parse(text);
			super.setValue(parse);
		} catch (ParseException e) {
			e.printStackTrace();
		}

	}
}
